package top.yxqz.spring.transaction.annotation.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import top.yxqz.spring.transaction.annotation.service.BookService;

/**
 * @author: 余小小
 * @date: 2023/4/20
 * @description：
 */
@Controller
public class BookController {

    @Autowired
    @Qualifier("bookService")
    public BookService bookService;


    @Autowired
    @Qualifier("bookServicexml")
    private BookService bookServicebyxml;

    /**
     * 通过注解的方式实现买书的事务案列
     * @param userId
     * @param bookId
     */

    public void buyBook(Integer userId, Integer bookId) {
        System.out.println("使用注解的方式实现买书的事务案列");

//    1.调用图书服务层
        bookService.buyBook(userId, bookId);
    }

    /**
     * 通过XML的方式实现买书的事务案列
     * @param userId
     * @param bookId
     */
    public void buyBookByXml(Integer userId, Integer bookId) {
        System.out.println("使用XML的方式实现买书的事务案列");
        bookServicebyxml.buyBook(userId, bookId);
    }
}
